//
//  WJCustomCodeTableViewController.m
//  JerryIos
//
//  Created by 王军 on 2018/2/2.
//  Copyright © 2018年 王军. All rights reserved.
//

#import "WJCodeTableController.h"
#import "WJCodeTableCell.h"
#import "WJPerson.h"

@interface WJCodeTableController ()

@property (nonatomic, strong) NSArray *personArray;

@end

@implementation WJCodeTableController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //取消系统自带的分隔线。
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    //把tableView的背景色设置为分割线的颜色。
    self.tableView.backgroundColor = WJColor(220, 220, 221);
}

- (NSArray *)personArray {
    if (_personArray == nil) {
        WJPerson *person1 = [[WJPerson alloc] init];
        person1.icon = @"icon_home";
        person1.name = @"aaa";
        person1.text = @"qwertyuiophggfff";
        person1.vip = YES;
        
        WJPerson *person2 = [[WJPerson alloc] init];
        person2.icon = @"icon_home";
        person2.name = @"bbb";
        person2.text = @"qwertyubbbbbbbbbbbbbbbiophggfff";
        person2.vip = NO;
        person2.pic = @"icon_mail";
        
        WJPerson *person3 = [[WJPerson alloc] init];
        person3.icon = @"icon_home";
        person3.name = @"ccc";
        person3.text = @"qwertyuioph55555ggfff";
        person3.vip = NO;

        
        //计算每个控件的frame
        [person1 calculateFrame];
        [person2 calculateFrame];
        [person3 calculateFrame];
        
        NSMutableArray *mutPersonArray = [NSMutableArray array];
        [mutPersonArray addObject:person1];
        [mutPersonArray addObject:person2];
        [mutPersonArray addObject:person3];
        
        _personArray = mutPersonArray;
    }
    return _personArray;
}

#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.personArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    WJCodeTableCell *cell = [WJCodeTableCell cellWithTableView:tableView];
    cell.person = self.personArray[indexPath.row];
    return cell;
}

#pragma mark - Table view delgate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    WJPerson *person = self.personArray[indexPath.row];
    return person.cellHeight;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

@end
